from datetime import datetime, timedelta

smhdy = input().split()
curr = datetime(year=2023, month=1, day=1, hour=0, minute=0, second=0)

result = 0
# 翻译成列表
t = []
for clock in smhdy:

    if '-' in clock:
        start, end = clock.split('-')
        time = set(range(int(start), int(end) + 1))
    elif ',' in clock:
        timepeiord = clock.split(',')
        time = set(map(int, timepeiord))
    elif clock == '*':
        time = set('*')
    else:
        time = {int(clock)}
    t.append(time)

SS, MM, HH, DD, mm = t
end = datetime(year=2023, month=12, day=31, hour=23, minute=59, second=59)
valid_days = 0
while curr <= end:
    month_ = curr.month
    day = curr.day

    # 先找出所有满足的日期
    if day in DD and month_ in mm:
        valid_days += 1
    elif day in DD and mm == {'*'}:
        valid_days += 1
    elif DD == {'*'} and month_ in mm:
        valid_days += 1
    elif DD == mm == {'*'}:
        valid_days += 1
    curr += timedelta(days=1)

# 计算一天有几个合法时刻
curr = datetime(year=2023, month=1, day=1, hour=0, minute=0, second=0)
end = datetime(year=2023, month=1, day=1, hour=23, minute=59, second=59)
while curr <= end:
    hour = curr.hour
    minute = curr.minute
    second = curr.second
    if hour in HH and minute in MM and second in SS:
        result += 1
    curr += timedelta(seconds=1)
print(result * valid_days)
